package january.Test_1_28;

import java.util.Scanner;

public class TestMain {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[100000];
        arr[0] = 0;
        arr[1] = 1;
        int min = 0;
        for(int i = 2; i < arr.length; i++) {
            arr[i] = arr[i - 1] + arr[i - 2];
            if(arr[i - 1] <= n && arr[i] >= n) {
                min = Math.min(n - arr[i - 1],arr[i] - n);
                break;
            }
        }
        System.out.println(min);
    }
}
